<?php
namespace Admin\Controller;
use Common\Controller\AuthController;
use Think\Controller;
class AboutController extends AuthController
{
    public  function index(){
        if(IS_POST){
            $m = M('about');
            if (!$m->autoCheckToken($_POST)) {
                $this->error('表单令牌错误', 0, 0);
            }else{
                $data=I();
                $data['add_time']=time();
                $data['images'] = base64ToImage($data['images']);
                if($result=M('about')->where(array('id'=>1))->find()){
                    if($result=$m->where(array('id'=>1))->save($data)){
                        $this->error('修改成功');
                    }
                    else{
                        $this->error('修改失败');
                    }
                }else{
                    $data['id']=1;
                    if($result=$m->add($data)){
                        $this->error('添加成功');
                    }
                    else{
                        $this->error('添加失败');
                    }
                }
            }
        }else{
          if($result=M('about')->where(array('id'=>1))->find()){
              $this->assign('images',$result['images']);
             $this->assign('data',$result);
              $this->display();
          }else{
              $this->display();
          }
        }

    }

}